Skip to content

Authentication improvements - OAuth Login #1511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 23, 2020

Conversation

catarak
Copy link
Member

@catarak catarak commented Jul 22, 2020

Fixes #915, Re: #1317

I discovered a bug with respect to email address duplications and OAuth login, so this PR addresses that, and cleans up the flow and language for linking social accounts from the Account Settings page.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • is from a uniquely-named feature branch and has been rebased on top of the latest master. (If I was asked to make more changes, I have made sure to rebase onto master then too)
  • is descriptively named and links to an issue number, i.e. Fixes #123

@catarak catarak requested a review from andrewn July 22, 2020 18:15
@@ -31,22 +42,35 @@ const StyledButton = styled(Button)`
width: ${remSize(300)};
`;

function SocialAuthButton({ service }) {
function SocialAuthButton({ service, link, connected }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a while thinking does link mean that this button's an href? What is it linking to? Maybe it's just pre morning-coffee.

Perhaps instead of link, just the "connected" prop is enough to change the label type. If connected is null then display the login label otherwise display the connect/connected labels?

Copy link
Member Author

@catarak catarak Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm attempting to account for here is two different display options for the SocialAuthButton:

  • One for the Login/Signup Page
  • One for the Account Settings page, which uses the word "Link" rather than "Login". When the auth button is in "link" mode, it shows that a social account can either be "connected" or "not connected".
    So maybe this just needs to be changed to use better named variables?

* @callback [cb] - Optional error-first callback that passes User document
* @return {Promise<Object>} - Returns Promise fulfilled by User document
*/
userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, cb) {
userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, caseInsensitive, cb) {
const isEmail = value.indexOf('@') > -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We validate usernames not containing "@" chars in the client but I wonder whether this should also happen in the mongoose User model?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean validating a username when saving a (new or existing) User document?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Just to ensure these username rules are respected at the core of the app.

user.name = profile.displayName;
user.verified = User.EmailConfirmation.Verified;
user.save(saveErr => done(null, user));
let { username } = profile;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about when this flow will be triggered? If the user does not have an Editor account with the same email as their Github account?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's expected that this would trigger when a user is registering for the Editor with a GitHub account, i.e. they clicked "Login with GitHub" from the Signup Page.

This just reminded me that I should test if linking social accounts works properly if the email they registered with for the Editor is different from the email for their GItHub/Google Account.

@catarak
Copy link
Member Author

catarak commented Aug 6, 2020

I tested creating an account with a different email from the social account the user wants to link, and it will link the social account to the registered account matching the social's email, not the account the user explicitly tried to link to. So that's a bug 😄

@andrewn
Copy link
Member

andrewn commented Sep 10, 2020

I tested creating an account with a different email from the social account the user wants to link, and it will link the social account to the registered account matching the social's email, not the account the user explicitly tried to link to. So that's a bug 😄

Is there a way to write a test for this controller/passport functionality to help verify these different conditions? It's a bit tricky as it calls out to mongo quite a lot but it might be worth it?

@catarak
Copy link
Member Author

catarak commented Sep 10, 2020

Is there a way to write a test for this controller/passport functionality to help verify these different conditions? It's a bit tricky as it calls out to mongo quite a lot but it might be worth it?

That's probably a good idea, I was testing this by having an open connection to the MongoDB (on mlab), then deleting the GitHub key and trying to re-link the account.

@catarak
Copy link
Member Author

catarak commented Sep 14, 2020

Hey @oruburos! I'd like to add some Spanish translations in this PR, and if you could help out, that would be great! Specifically with the following phrases:

  • 'Connect GitHub Account'
  • 'Re-link GitHub Account'
  • 'Connect Google Account'
  • 'Re-link Google Account'

Thank you!! If you'd prefer I'd not ask you for translations in the future let me know, I'm happy to ask other Spanish-speaking folks in the community.

@oruburos
Copy link
Collaborator

Hi @catarak, here are my suggestions

  • 'Connect GitHub Account'
    'Conecta Cuenta Github'
  • 'Re-link GitHub Account'
    'Vuelve a Vincular Cuenta Github'
  • 'Connect Google Account'
    'Conecta con Cuenta Google'
  • 'Re-link Google Account'
    'Vuelve a Vincular Cuenta Google '

@catarak
Copy link
Member Author

catarak commented Sep 18, 2020

@oruburos if you're up for it, I could use a few more translations:

  • 'Unlink (GitHub/Google) Account'
  • 'Error Linking Account'
  • 'There was a problem linking your (GitHub/Google) account to your p5.js Web Editor account. Your (GitHub/Google) account has already been linked to another p5.js Web Editor account.'

Thank you for your help!

@oruburos
Copy link
Collaborator

@catarak Sure, here are my suggestions

  • 'Unlink (GitHub/Google) Account'
  • 'Desvincular Cuenta (Github/Google)'
  • 'Error Linking Account'
  • 'Error Vinculando Cuenta'
  • 'There was a problem linking your (GitHub/Google) account to your p5.js Web Editor account. Your (GitHub/Google) account has already been linked to another p5.js Web Editor account.'
  • 'Hubo un problema vinculando tu cuenta de (GitHub/Google) con tu cuenta del Editor Web p5.js. Tu cuenta de (GitHub/Google) había sido vinculada previamente con otra cuenta del Editor Web p5.js.'

@catarak catarak merged commit 1d172ad into develop Sep 23, 2020
@montoyamoraga
Copy link
Member

@catarak, i am going through the branches, i think this one is ready to be deleted :)

@catarak catarak deleted the chore/authentication-improvements branch December 17, 2020 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link OAuth accounts from user settings page
4 participants